﻿using Ninject.Modules;
using PAP.Application.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ninject.Extensions.Conventions;
using PAP.Domain.Core.Repositories;
using NHibernate;
using System.Configuration;
using PAP.Infrastructure.DataAccess.NH.Domain.Mappings.UserAccount;

namespace PAP.Infrastructure.DataAccess.NH.Domain
{
    public class ModuleActivation : NinjectModule
    {
        public override void Load()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["PAPDomain"].ConnectionString;
            Kernel.Bind<ISessionFactory>()
                .ToMethod(x => SessionFactory.CreateMSSQL2008SessionFactory(connectionString, m => m.FluentMappings.AddFromAssemblyOf<UserMap>()));

            Kernel.Bind(x =>
                {
                    x.FromThisAssembly()
                        .SelectAllClasses()
                        .InheritedFrom(typeof(IRepository<>))
                        .BindDefaultInterface();
                });
        }
    }
}
